import java.util.ArrayList;
import java.util.Scanner;

public class Test {

    public static int count = 0;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        count = isBig(N);
        while(count >= 10) {
            count = isBig(count);
        }
        System.out.println(count);
    }

    public static int isBig(int N) {
        int counts = 0;
        while(N > 0) {
            counts+=N%10;
            N/=10;
        }
        return counts;
    }
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int count = 0;
        int n = scan.nextInt();

        for(int i = 2;i <= n;i++) {
            int j = 2;
            boolean bool = true;
            while(j < Math.sqrt(i)) {
                if(i % j == 0) {
                    bool = false;
                    break;
                }
                j++;
            }
            if(bool) {
                count++;
            }
        }

        System.out.println(count);
        scan.close();
    }
}
